import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    songList: [],
    fullScreen: false, // 全屏播放器
    currentIndex: 0,//当前音乐index
    lyric: '',//歌词
    isPlayList: false, //列表显示
    isPlay: true,//暂停&播放
    isMode: 0, //播放方式
    currentTime: '',// 播放时的时间 
  },
  mutations: {
    //获取数据
    setData(state, payload) {
      state.currentIndex = payload.index
      state.songList = payload.songList
    },
    isMode(state, payload) {
      payload.index == 2 ? state.isMode = 0 : state.isMode++
    },
    getLyric(state, payload) {
      state.lyric = payload.lyric
    },
    getCurrentTime(state, payload) {
      state.currentTime = payload.currentTime
    },
    fullScreen(state) {
      state.fullScreen = true
    },
    isPlay(state) {
      state.isPlay = !state.isPlay
    },
    //下一首
    nextIndex(state) {
      switch (state.isMode) {
        case 0:
          state.currentIndex = Math.floor(Math.random() * state.songList.length);
          break;
        case 1:
        case 2:
          state.currentIndex === state.songList.length ?
            state.currentIndex = 0 :
            state.currentIndex++;
          break;
      }
    },
    //上一首
    previousIndex(state) {
      state.currentIndex === 0 ?
        state.currentIndex = state.songList.length :
        state.currentIndex--
    },
    //播放列表
    isPlayList(state, payload) {
      state.isPlayList = payload.isPlayList
      state.isPlayList = true
    },
    //列表隐藏
    isshadeClick(state) {
      state.isPlayList = false
    },
    //播放列表item点击
    songListClick(state, payload) {
      state.currentIndex = payload.index
    },
    //删除列表item
    deleteItem(state, payload) {
      state.songList.splice(payload.index, 1)
      if (payload.index < state.currentIndex) {
        state.currentIndex--
      }
    },
    //隐藏全屏
    backClick(state) {
      state.fullScreen = false
    },
    isFullScreen(state) {
      state.fullScreen = true
    }
  },
  actions: {
  },
  modules: {
  }
})
